TK!2
=v
#1
:n
P
:v
.9009398190388688
:s
o
#2
:n
a
:v
5
:s
i
:c
half n
#3
:n
x
:v
8
:s
i
:c
half Chi2
=u
=l
=f
#1
:n
Igamma
:c
Incomplete gamma function
:t
Procedure
:i
a,x
:o
z
#2
:n
IgammaCF
:c
Incomplete gamma function, CF part
:t
Procedure
:i
a,b,A2,B2,A3,B3,f,f1
:o
z
#1
:n
Igamma
:z
" Description:
" The incomplete gamma function is defined as
"                          x
"                         ô
"                    1    ³  -t  a-1
"      P(a,x)  =  ÄÄÄÄÄÄÄ ³ e   t    dt
"                   â(a)  ³
"                         õ0

" It is related to the Chi-Square cumulative distribution function as
" follows:
"            P(a,x)  =  P(n/2,Xý/2) ,  where  n  - degrees of freedom.

" The function is evaluated using series representation for  x < a+1 , 
" and continued fraction representation (recurrence formula, recursive
" procedure) for  x ò a+1 .

" Supporting function: ingammaCF

exg:= exp(-x)*x^a/gamma(a)
if x < a+1 goto S
z:= 1 - exg*IgammaCF(1-a,x,1,x,0,1,1/x,0)   " continued fraction
return                                      " representation

S: b:= a
   s:= 1/b
   p:= s
L: b:= b + 1
   p:= p*x/b
   s:= s + p
   if p>s*1e-12 goto L
z:= exg*s                     " series representation
/E
E
#2
:n
IgammaCF
:z
if abs(f-f1)<1e-12 goto end         " precision check
A1:= A2 + a*A3
B1:= B2 + a*B3
A:= b*A1 + A2
B:= b*B1 + B2
f:= IgammaCF(a+1,b,A,B,A1,B1,A/B,f)  " recursive call
end: z:= f

" Note: This recursive procedure uses the continued fraction representation
"       and recurrence formulas; it is called by 'Igamma' when  x ò a+1 .
/E
E
=r
#1
:r
"  *** Incomplete Gamma Function and Chi-Square Probability Function ***
:s
C
#3
:r
P = Igamma(a,x)
=p
=t
=n
=g
#1
:c
.000001
:i
10
:v
Yes
:l
60
:f
66
:m
0
:w
80
:b
Yes
:a
Yes
:r
Yes
:h
No
:t
1
:n
Yes
:d
LPT1
%Br,f,0,1,0,1,0
%Ov,f,0,0,0,1,0
